package com.zendesk.maxwell.row;

import java.io.IOException;

/**
 * @Auther: miaoguoxin
 * @Date: 2021/12/20 22:05
 * @Description:
 */
public class RowMapBufferPlus extends RowMapBuffer {
	private Long beginRowTimestampMillis;
	private RowMap lastRowMap;
	private RowMap lastHeartbeatRowMap;
	private long rowMapNum;
	private String currentQuery;

	public RowMapBufferPlus(long maxInMemoryElements, float bufferMemoryUsage) {
		super(maxInMemoryElements, bufferMemoryUsage);
	}

	public RowMapBufferPlus(long maxInMemoryElements, float bufferMemoryUsage, Long beginRowTimestampMillis) {
		this(maxInMemoryElements, bufferMemoryUsage);
		this.beginRowTimestampMillis = beginRowTimestampMillis;
	}

	public String getCurrentQuery() {
		return currentQuery;
	}

	public void setCurrentQuery(String currentQuery) {
		this.currentQuery = currentQuery;
	}

	@Override
	public void add(RowMap rowMap) throws IOException {
		this.lastRowMap = rowMap;
		this.rowMapNum++;
	}

	@Override
	public Long size() {
		return rowMapNum;
	}

	@Override
	public RowMap getLast() {
		return this.lastRowMap;
	}

	public RowMap getLastHeartbeatRowMap() {
		return lastHeartbeatRowMap;
	}

	public void setLastHeartbeatRowMap(RowMap lastHeartbeatRowMap) {
		this.lastHeartbeatRowMap = lastHeartbeatRowMap;
	}

	public Long getTxTimeSpend() {
		return this.getLast().getTimestampMillis() - this.beginRowTimestampMillis;
	}
}
